package com.socket3;

import java.util.ArrayList;

import com.socket.entity.BmsEntity;
import com.socket.entity.MapEntity;
import com.socket.entity.PositionOffset;
import com.socket.entity.SpatEntity;
import com.socket.entity.TimEntity;

public class DataParse_2 {
	
	
	public static void main(String[] args) {
//		System.out.println(getSpat().toString());
//		System.out.println(getMap().toString());
//		System.out.println(getBsm().toString());
		
		System.out.println(getTim("").toString());
	}
	public 	static ArrayList<SpatEntity> getSpat(){
		String data=""
				+"305480010DA24F304D8102"
				+ "007B"//id 22 26
				+ "820100A544300F8201"
				+ "01"//laneSet 44 46
				+ "8301"
				+ "01"// 50 52
				+ "8601"
				+ "1D"// 5658
				+ "8701038b0103300f8201"
				+ "02"//laneSet  78 80
				+ "8301"
				+ "04"//84 86
				+ "8601"
				+ "6c"//90 92
				+ "8701038b0103300f8201"
				+ "03"//laneSet 112 114 
				+ "8301"
				+ "02"//118 120
				+ "8601"
				+ "1d"// 124 126
				+ "8701038b0103300F8201"
				+ "04"//laneSet  146 148
				+ "8301"
				+ "02"//152 154
				+ "8601"
				+ "1D"// 158 160
				+ "8701038b0103";
		String id = data.substring(22, 26);
		String laneSet = data.substring(44, 46);
		String currState = data.substring(50, 52);
		String timeToChange = data.substring(56, 58);

		String laneSet1 = data.substring(78, 80);
		String currState1 = data.substring(84, 86);
		String timeToChange1 = data.substring(90, 92);

		String laneSet2 = data.substring(112, 114);
		String currState2 = data.substring(118, 120);
		String timeToChange2 = data.substring(124, 126);

		String laneSet3 = data.substring(146, 148);
		String currState3 = data.substring(152, 154);
		String timeToChange3 = data.substring(158, 160);

		ArrayList<SpatEntity> list = new ArrayList<SpatEntity>();
		SpatEntity entity = new SpatEntity(Integer.parseInt(id, 16), laneSet,
				Integer.parseInt(currState, 16), Integer.parseInt(timeToChange,
						16));

		SpatEntity entity1 = new SpatEntity(Integer.parseInt(id, 16), laneSet1,
				Integer.parseInt(currState1, 16), Integer.parseInt(
						timeToChange1, 16));

		SpatEntity entity2 = new SpatEntity(Integer.parseInt(id, 16), laneSet2,
				Integer.parseInt(currState2, 16), Integer.parseInt(
						timeToChange2, 16));

		SpatEntity entity3 = new SpatEntity(Integer.parseInt(id, 16), laneSet3,
				Integer.parseInt(currState3, 16), Integer.parseInt(
						timeToChange3, 16));
		list.add(entity);
		list.add(entity1);
		list.add(entity2);
		list.add(entity3);
		return list;
		
	}
	
	public static ArrayList<MapEntity>  getMap(){
		String data=""
				+"30820113800107810100830103A58201023081FF8102"
				+ "007B"//id 44 48
				+ "A20C8004"
				+ "191B0080"//
				+ "8104"
				+ "CE74E500"
				+ "A781EA3039A237800A4E6F727468626F756E648101"
				+ "01"//id
				+ "A22630248001"
				+ "01"//
				+ "8102016E820102A3180406"
				+ "E1B1CBF70001"//node
				+ "0406"
				+ "62139F380002"//
				+ "0406"
				+ "AF339F380001"//
				+ "3038A236800945617374626F756E648101"
				+ "02"//id
				+ "A22630248001"
				+ "02"//
				+ "8102"
				+ "016E"//
				+ "820102A3180406"
				+ "D10459060001"//
				+ "0406"
				+ "50DA9F380001"//
				+ "0406"
				+ "50EC9F380000"//
				+ "3039A237800A536F757468626F756E648101"
				+ "03"//id
				+ "A22630248001"
				+ "03"//
				+ "8102"
				+ "016E"//
				+ "820102A3180406"
				+ "C32C2AC00001"//
				+ "0406"
				+ "5E79122A0001"//
				+ "0406"
				+ "AF33AF650001"//
				+ "3038A236800957657374626F756E64810104A22630248001"
				+ "04"//id
				+ "8102"
				+ "016E"//
				+ "820102A3180406"
				+ "E038795E0001"//
				+ "0406"
				+ "50C4122A0001"//
				+ "0406"
				+ "9A5460C80001"//
				+ "87023500";
		
		String id = data.substring(44, 48);
		String lat = data.substring(56, 64);
		String lon = data.substring(68, 76);
		MapEntity entity = new MapEntity(Long.parseLong(lat, 16),
				Long.parseLong(lon, 16), Integer.parseInt(id, 16));
		// id1
		String name1 = data.substring(94, 114);
		String id1 = data.substring(118, 120);
		String laneNumber1 = data.substring(132, 134);
		String laneWidth1 = data.substring(138, 142);
		String laneAttributes1 = data.substring(146, 148);
		ArrayList<PositionOffset> list1 = new ArrayList<PositionOffset>();
		String x11 = data.substring(156, 160);
		String y11 = data.substring(160, 164);
		String z11 = data.substring(164, 168);
		PositionOffset offset11 = new PositionOffset(Integer.parseInt(x11, 16),
				Integer.parseInt(y11, 16), Integer.parseInt(z11, 16));

		String x12 = data.substring(172, 176);
		String y12 = data.substring(176, 180);
		String z12 = data.substring(180, 184);
		PositionOffset offset12 = new PositionOffset(Integer.parseInt(x12, 16),
				Integer.parseInt(y12, 16), Integer.parseInt(z12, 16));

		String x13 = data.substring(188, 192);
		String y13 = data.substring(192, 196);
		String z13 = data.substring(196, 200);
		PositionOffset offset13 = new PositionOffset(Integer.parseInt(x13, 16),
				Integer.parseInt(y13, 16), Integer.parseInt(z13, 16));
		list1.add(offset11);
		list1.add(offset12);
		list1.add(offset13);

		MapEntity entity1 = new MapEntity(Integer.parseInt(id1, 16),
				Integer.parseInt(laneNumber1, 16), Integer.parseInt(laneWidth1,
						16), Integer.parseInt(laneAttributes1, 16), list1,
				name1);
		// id2
		String name2 = data.substring(212, 230);
		String id2 = data.substring(234, 236);
		String laneNumber2 = data.substring(248, 250);
		String laneWidth2 = data.substring(254, 258);
		String laneAttributes2 = data.substring(262, 264);
		ArrayList<PositionOffset> list2 = new ArrayList<PositionOffset>();
		String x21 = data.substring(272, 276);
		String y21 = data.substring(276, 280);
		String z21 = data.substring(280, 284);
		PositionOffset offset21 = new PositionOffset(Integer.parseInt(x21, 16),
				Integer.parseInt(y21, 16), Integer.parseInt(z21, 16));

		String x22 = data.substring(288, 292);
		String y22 = data.substring(292, 296);
		String z22 = data.substring(296, 300);
		PositionOffset offset22 = new PositionOffset(Integer.parseInt(x22, 16),
				Integer.parseInt(y22, 16), Integer.parseInt(z22, 16));

		String x23 = data.substring(304, 308);
		String y23 = data.substring(308, 312);
		String z23 = data.substring(312, 316);
		PositionOffset offset23 = new PositionOffset(Integer.parseInt(x23, 16),
				Integer.parseInt(y23, 16), Integer.parseInt(z23, 16));
		list2.add(offset21);
		list2.add(offset22);
		list2.add(offset23);

		MapEntity entity2 = new MapEntity(Integer.parseInt(id2, 16),
				Integer.parseInt(laneNumber2, 16), Integer.parseInt(laneWidth2,
						16), Integer.parseInt(laneAttributes2, 16), list2,
				name2);

		// //id3
		String name3 = data.substring(212, 230);
		String id3 = data.substring(352, 354);
		String laneNumber3 = data.substring(366, 368);
		String laneWidth3 = data.substring(372, 376);
		String laneAttributes3 = data.substring(380, 382);
		ArrayList<PositionOffset> list3 = new ArrayList<PositionOffset>();
		String x31 = data.substring(390, 394);
		String y31 = data.substring(394, 398);
		String z31 = data.substring(398, 402);
		PositionOffset offset31 = new PositionOffset(Integer.parseInt(x31, 16),
				Integer.parseInt(y31, 16), Integer.parseInt(z31, 16));
		String x32 = data.substring(406, 410);
		String y32 = data.substring(410, 414);
		String z32 = data.substring(414, 418);
		PositionOffset offset32 = new PositionOffset(Integer.parseInt(x32, 16),
				Integer.parseInt(y32, 16), Integer.parseInt(z32, 16));

		String x33 = data.substring(422, 426);
		String y33 = data.substring(426, 430);
		String z33 = data.substring(430, 434);
		PositionOffset offset33 = new PositionOffset(Integer.parseInt(x33, 16),
				Integer.parseInt(y33, 16), Integer.parseInt(z33, 16));
		list3.add(offset31);
		list3.add(offset32);
		list3.add(offset33);

		int id33 = Integer.parseInt(id3, 16);
		int laneNumber33 = Integer.parseInt(laneNumber3, 16);
		int laneWidth33 = Integer.parseInt(laneWidth3, 16);
		int laneAttributes33 = Integer.parseInt(laneAttributes3, 16);

		MapEntity entity3 = new MapEntity(id33, laneNumber33, laneNumber33,
				laneAttributes33, list3, name3);

		// id4
		String name4 = data.substring(446, 464);
		String id4 = data.substring(468, 470);
		String laneNumber4 = data.substring(482, 484);
		String laneWidth4 = data.substring(488, 492);
		String laneAttributes4 = data.substring(496, 498);
		ArrayList<PositionOffset> list4 = new ArrayList<PositionOffset>();
		String x41 = data.substring(506, 510);
		String y41 = data.substring(510, 514);
		String z41 = data.substring(514, 518);

		PositionOffset offset41 = new PositionOffset(Integer.parseInt(x41, 16),
				Integer.parseInt(y41, 16), Integer.parseInt(z41, 16));
		String x42 = data.substring(522, 526);
		String y42 = data.substring(526, 530);
		String z42 = data.substring(530, 534);
		PositionOffset offset42 = new PositionOffset(Integer.parseInt(x42, 16),
				Integer.parseInt(y42, 16), Integer.parseInt(z42, 16));

		String x43 = data.substring(538, 542);
		String y43 = data.substring(542, 546);
		String z43 = data.substring(546, 550);
		PositionOffset offset43 = new PositionOffset(Integer.parseInt(x43, 16),
				Integer.parseInt(y43, 16), Integer.parseInt(z43, 16));
		list4.add(offset41);
		list4.add(offset42);
		list4.add(offset43);

		MapEntity entity4 = new MapEntity(Integer.parseInt(id4, 16),
				Integer.parseInt(laneNumber4, 16), Integer.parseInt(laneWidth4,
						16), Integer.parseInt(laneAttributes4, 16), list4,
				name4);

		ArrayList<MapEntity> list = new ArrayList<MapEntity>();
		list.add(entity);
		list.add(entity1);
		list.add(entity2);
		list.add(entity3);
		list.add(entity4);
		return list;
	}
		public static BmsEntity getBsm(){
			String data=""
			+"6174e41fabc418"
			+ "1280769c"// 14 22
			+ "48448ca2"// 22 30
			+ "00c8"//30 34
			+ "78184000"
			+ "e001"//42 46
			+ "70807ffff907d1817fff0000"
			+ "2d014a";//70 76
			
			
			String lat = data.substring(14, 14 + 8);
			String lon = data.substring(22, 22 + 8);
			String altitude = data.substring(30, 30 + 4);
			String speed = data.substring(42, 42 + 4);
			String carWidth = data.substring(70, 70 + 3);
			String carLong = data.substring(73, 73 + 3);

			BmsEntity entity = new BmsEntity(Long.parseLong(lat, 16),
					Long.parseLong(lon, 16), Integer.parseInt(altitude, 16),
					Integer.parseInt(speed, 16), Integer.parseInt(carWidth, 16),
					Integer.parseInt(carLong, 16));
			return entity;
		}
		
		
		
		public static TimEntity getTim(String data) {
			data = "" + "30818e80" + "01108109" + "00000000" + "005f4943"
					+ "45830101" + "a4773075" + "800102a1" + "1ba119a0" + "108004"
					+ "1298b13a"// 70 78
					+ "8104" + "4863674c"// 82 90
					+ "8202" + "00a5"// 94 98
					+ "8102" + "000f"// 102 106
					+ "8201" + "02"// 110 112
					+ "8202" + "07e0"// 116 120
					+ "8303" + "05aeb0"// 124 130
					+ "8402" + "7d00"// 134 138
					+ "8501" + "02"// 142 144
					+ "a6108004" + "1298b13a"// 152 160
					+ "8104" + "4863674c"// 164 172
					+ "8202" + "00a5"// 176 180
					+ "8702" + "0258"// 184 188
					+ "8801" + "00"// 192 194
					+ "a91e301c8002" + "000f"// 206 210
					+ "a216a014a3120404" + "14090d8e"// 226 234
					+ "0404" + "17260fa1"// 238 246
					+ "0404" + "12b30c89"// 250 258
					+ "aa0aa0083006a0048002171885020000";

			String lat = data.substring(70, 78);
			String lon = data.substring(82, 90);
			String altitude = data.substring(94, 98);
			String viewAngle = data.substring(102, 106);
			String mutcdCode = data.substring(110, 112);

			String startYear = data.substring(116, 120);
			String startTime = data.substring(124, 130);
			String durationTime = data.substring(134, 138);

			String priority = data.substring(142, 144);// 优先级

			String commonAnchor_lat = data.substring(152, 160);// 起点
			String commonAnchor_lon = data.substring(164, 172);
			String commonAnchor_elevation = data.substring(176, 180);
			String commonLaneWidth = data.substring(184, 188);// 车道宽度
			String commonDirectionality = data.substring(192, 194);
			ArrayList<PositionOffset> nodeList = new ArrayList<PositionOffset>();//
			String x = data.substring(226, 230);
			String y = data.substring(230, 234);

			String x1 = data.substring(238, 242);
			String y1 = data.substring(242, 246);

			String x2 = data.substring(250, 254);
			String y2 = data.substring(254, 258);

			PositionOffset offset = new PositionOffset(Integer.parseInt(x, 16),
					Integer.parseInt(y, 16));
			PositionOffset offset1 = new PositionOffset(Integer.parseInt(x1, 16),
					Integer.parseInt(y1, 16));
			PositionOffset offset2 = new PositionOffset(Integer.parseInt(x2, 16),
					Integer.parseInt(y2, 16));

			nodeList.add(offset);
			nodeList.add(offset1);
			nodeList.add(offset2);
			TimEntity entity = new TimEntity(Integer.parseInt(lat, 16),
					Integer.parseInt(lon, 16), Integer.parseInt(altitude, 16),
					Integer.parseInt(viewAngle, 16),
					Integer.parseInt(mutcdCode, 16),
					Integer.parseInt(startYear, 16),
					Integer.parseInt(startTime, 16), Integer.parseInt(durationTime,
							16), Integer.parseInt(priority, 16), Integer.parseInt(
							commonAnchor_lat, 16), Integer.parseInt(
							commonAnchor_lon, 16), Integer.parseInt(
							commonAnchor_elevation, 16), Integer.parseInt(
							commonLaneWidth, 16), Integer.parseInt(
							commonDirectionality, 16), nodeList);
			return entity;

		}
		
		
		
		
}
